package me.com.yf.util;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;

public class Player {

	public static void PlaySystemNotificationRing(Context c) {
		try {
			AssetManager assetManager = c.getAssets();
			AssetFileDescriptor fileRight = assetManager.openFd("scan_right.wav");
			MediaPlayer mediaPlayer = new MediaPlayer();
			mediaPlayer.setDataSource(fileRight.getFileDescriptor(), fileRight.getStartOffset(), fileRight.getLength());
			mediaPlayer.prepare();
			mediaPlayer.setOnCompletionListener(new OnCompletionListener() {

				@Override
				public void onCompletion(MediaPlayer mp) {
					// TODO Auto-generated method stub
					mp.release();
				}
			});
			mediaPlayer.setOnErrorListener(new OnErrorListener() {

				@Override
				public boolean onError(MediaPlayer mp, int what, int extra) {
					// TODO Auto-generated method stub
					mp.release();
					return false;
				}
			});
			mediaPlayer.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void PlaySytemErrorRing(Context c) {
		try {
			AssetManager assetManager = c.getAssets();
			AssetFileDescriptor fileError = assetManager.openFd("scan_wrong.wav");
			MediaPlayer mediaPlayer = new MediaPlayer();
			mediaPlayer.setDataSource(fileError.getFileDescriptor(), fileError.getStartOffset(), fileError.getLength());
			mediaPlayer.prepare();
			mediaPlayer.setOnCompletionListener(new OnCompletionListener() {

				@Override
				public void onCompletion(MediaPlayer mp) {
					// TODO Auto-generated method stub
					mp.release();
				}
			});
			mediaPlayer.setOnErrorListener(new OnErrorListener() {

				@Override
				public boolean onError(MediaPlayer mp, int what, int extra) {
					// TODO Auto-generated method stub
					mp.release();
					return false;
				}
			});
			mediaPlayer.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
